package com.df.ez_game.server;

import com.df.ez_game.server.logic.LogicServerNode;
import com.df.ez_game.server.msg.client.ClientReqMsg;
import com.df.ez_game.server.msg.client.ClientRespMsg;
import com.df.ez_game.server.req_metadata.EzMethodData;
import com.df.ez_game.tools.EzConstant;
import io.netty.channel.ChannelHandlerContext;

public class MsgCommonHandle {
    /**
     * 单体运行时，消息队列可能已满，表示服务器繁忙
     * @return
     */
    public static void serverIsBusy(LogicServerNode serverNode, ClientReqMsg clientReqMsg, ChannelHandlerContext ctx){
        ClientRespMsg res = new ClientRespMsg();
        res.setCmd(clientReqMsg.getCmd());
        res.setCode(EzConstant.ErrorRespCode.serverIsBusy);
        res.setMsgSerial(clientReqMsg.getMsgSerial());
        ctx.channel().writeAndFlush(res);
    }

    /**
     * 单体运行时，cmd未找到元数据
     * @param serverNode
     * @param ctx
     * @param reqMsg
     */
    public static void cmdNotFound(ServerNode serverNode, ChannelHandlerContext ctx, ClientReqMsg reqMsg) {
        ClientRespMsg res = new ClientRespMsg();
        res.setCmd(reqMsg.getCmd());
        res.setCode(EzConstant.ErrorRespCode.cmdNotFound);
        res.setMsgSerial(reqMsg.getMsgSerial());
        ctx.channel().writeAndFlush(res);
    }

    public static void paramIsEmpty(ServerNode serverNode, ChannelHandlerContext ctx, ClientReqMsg reqMsg) {

        ClientRespMsg res = new ClientRespMsg();
        res.setCmd(reqMsg.getCmd());
        res.setCode(EzConstant.ErrorRespCode.paramIsEmpty);
        res.setMsgSerial(reqMsg.getMsgSerial());
        ctx.channel().writeAndFlush(res);
    }

    public static void paramParseError(ServerNode serverNode, ChannelHandlerContext ctx, ClientReqMsg reqMsg) {
        ClientRespMsg res = new ClientRespMsg();
        res.setCmd(reqMsg.getCmd());
        res.setCode(EzConstant.ErrorRespCode.paramParseError);
        res.setMsgSerial(reqMsg.getMsgSerial());
        ctx.channel().writeAndFlush(res);
    }

    public static void paramValidateFail(ServerNode serverNode, ChannelHandlerContext ctx, ClientReqMsg reqMsg) {
        ClientRespMsg res = new ClientRespMsg();
        res.setCmd(reqMsg.getCmd());
        res.setCode(EzConstant.ErrorRespCode.paramParseError);
        res.setMsgSerial(reqMsg.getMsgSerial());
        ctx.channel().writeAndFlush(res);
    }

    public static void printMsgDetails(ServerNode serverNode, ClientReqMsg reqMsg, ChannelHandlerContext ctx, boolean success, EzMethodData methodData, String reason) {
//            ┏━━━━━ REQ ━━━━━ [ver:0]━━━━━ [cmd:1-0 0x1001] ━━━━━ [size:128B] ━━━━━ [cost:12.3ms] ━━━━━━
//            ┣ 位置: DemoAction.java:5 (here)
//            ┣ 用户: userId=1 | traceId=956230991452569600 | logicSvr=xxx逻辑服 | connId=76526c134cc
//            ┣ 参数: LoginVerifyMessage(jwt=hello, device="iOS", version=3.2.1)
//            ┣ 响应: UserMessage(name="Michael Jackson", gold=1500, items=[301,205])
//            ┣ 耗时: 业务=1ms | 网络=11.3ms | 总=12.3ms
//            ┣ 结果: fail | reason=参数解析错误
//            ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    }

//    public static void respErrorMsg()
}
